<?php

require_once 'common/conn.php';
if (isset($_GET['start'])) {
    $num = $_GET['start'];
} else {
    $num = 0;
}
if (isset($_GET['limit'])) {
    $count = $_GET['limit'];
}
if (isset($_GET['order'])) {
    $order = $_GET['order'];
}

if (isset($_GET['type'])) {
    $type = $_GET['type'];
}

$data = array();
if (is_numeric($num) && is_numeric($count)) {
    $db = new DBC();
    $sql = "SELECT * FROM t_product WHERE status = 1 AND top = 1 LIMIT " . $num . "," . $count;
    if (isset($order) && $order == "time") {
        $sql = "SELECT * FROM t_product WHERE status = 1 AND top = 1 ORDER BY createdate DESC LIMIT " . $num . "," . $count;
    } else if (isset($order) && $order == "code") {
        $sql = "SELECT * FROM t_product WHERE status = 1 AND top = 1 ORDER BY flashcode LIMIT " . $num . "," . $count;
    }

    if (isset($type)) {
        if ($type == "music") {
            $sql = "SELECT productid,flashcode,age,name,url,imageURL,version,size,type1,type2,downloadtimes "
                    . "FROM t_music WHERE status = 1 AND top = 1 ORDER BY createdate DESC LIMIT " . $num . "," . $count;
        } else if ($type == "animation") {
            $sql = "SELECT productid,flashcode,age,name,url,imageURL,version,size,type1,type2,downloadtimes "
                    . "FROM t_animation WHERE status = 1 AND top = 1 ORDER BY createdate DESC LIMIT " . $num . "," . $count;
        }
    }
    $data = $db->fetchData($sql);
}
echo json_encode($data);
?>